package com.sdr.sluicemapplugin.activities;

import com.sdr.xitang.R;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;


public class ZhaZhanController extends AppCompatActivity implements View.OnClickListener{

    private ImageView iv_control_gate_status_yuankongwei,iv_control_gate_status_zikongwei,iv_control_gate_status_shoukongwei,iv_control_gate_status_zhamenkai,
                        iv_control_gate_status_zhamenguan,iv_control_gate_status_zhamenting,iv_control_gate_status_quankai,iv_control_gate_status_quanguan,
                        iv_control_gate_status_guzhang,iv_control_gate_status_jinting;

    private TextView tv_control_gate_status_kaijiTM,tv_control_gate_status_guanjiTM;
    private EditText edt_control_gate_status_setKaidu,edt_control_gate_status_realKaidu;

    private Button btn_control_gate_status_TouRu,btn_control_gate_status_Exit,btn_control_gate_status_Open,btn_control_gate_status_Close,
                    btn_control_gate_status_Stop,btn_control_gate_status_Video;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zha_zhan_controller);
        initActionBar();
        initView();
        initData();
        initListener();
    }
    private void initActionBar() {
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#72D3E4")));
        actionBar.setCustomView(R.layout.baidumap_actionbar_custom);
        //设置右滑打开不可见
        actionBar.getCustomView().findViewById(R.id.iv_openRight).setVisibility(View.INVISIBLE);
        //设置标题文字
        TextView tv_titile = (TextView) actionBar.getCustomView().findViewById(R.id.tv_actionbar_title);
        tv_titile.setText("闸门控制");
        //设置返回按钮的监听事件
        actionBar.getCustomView().findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }


    private void initView() {
        iv_control_gate_status_yuankongwei = (ImageView) findViewById(R.id.iv_control_gate_status_yuankongwei);
        iv_control_gate_status_zikongwei = (ImageView) findViewById(R.id.iv_control_gate_status_zikongwei);
        iv_control_gate_status_shoukongwei = (ImageView) findViewById(R.id.iv_control_gate_status_shoukongwei);
        iv_control_gate_status_zhamenkai = (ImageView) findViewById(R.id.iv_control_gate_status_zhamenkai);
        iv_control_gate_status_zhamenguan = (ImageView) findViewById(R.id.iv_control_gate_status_zhamenguan);
        iv_control_gate_status_zhamenting = (ImageView) findViewById(R.id.iv_control_gate_status_zhamenting);
        iv_control_gate_status_quankai = (ImageView) findViewById(R.id.iv_control_gate_status_quankai);
        iv_control_gate_status_quanguan = (ImageView) findViewById(R.id.iv_control_gate_status_quanguan);
        iv_control_gate_status_guzhang = (ImageView) findViewById(R.id.iv_control_gate_status_guzhang);
        iv_control_gate_status_jinting = (ImageView) findViewById(R.id.iv_control_gate_status_jinting);

        tv_control_gate_status_kaijiTM = (TextView) findViewById(R.id.tv_control_gate_status_kaijiTM);
        tv_control_gate_status_guanjiTM = (TextView) findViewById(R.id.tv_control_gate_status_guanjiTM);

        edt_control_gate_status_setKaidu = (EditText) findViewById(R.id.edt_control_gate_status_setKaidu);
        edt_control_gate_status_realKaidu = (EditText) findViewById(R.id.edt_control_gate_status_realKaidu);

        btn_control_gate_status_TouRu = (Button) findViewById(R.id.btn_control_gate_status_TouRu);
        btn_control_gate_status_Exit = (Button) findViewById(R.id.btn_control_gate_status_Exit);
        btn_control_gate_status_Open = (Button) findViewById(R.id.btn_control_gate_status_Open);
        btn_control_gate_status_Close = (Button) findViewById(R.id.btn_control_gate_status_Close);
        btn_control_gate_status_Stop = (Button) findViewById(R.id.btn_control_gate_status_Stop);
        btn_control_gate_status_Video = (Button) findViewById(R.id.btn_control_gate_status_Video);
    }

    private void initData() {
    }

    private void initListener(){
        btn_control_gate_status_TouRu.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_control_gate_status_TouRu:
                //判断大小是否是在0~10之间
                String inputNum = edt_control_gate_status_setKaidu.getText().toString();
            if (!"".equals(inputNum)){
                if (isOpenDegree(inputNum)){
                    Toast.makeText(ZhaZhanController.this, "成功", Toast.LENGTH_SHORT).show();
                }else {
                    Toast.makeText(ZhaZhanController.this, "请输入0~10之间的数", Toast.LENGTH_SHORT).show();
                }
            }else {
                Toast.makeText(ZhaZhanController.this, "输入开度不能为空", Toast.LENGTH_SHORT).show();
            }
            break;
        }
    }


    private boolean isOpenDegree(String number){
        double num = Double.parseDouble(number);
        if (num>0 && num<=10){
            return true;
        }else {
            return false;
        }
    }
}
